package otherTabs;

import java.awt.BorderLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JTextField;
 /**
  * 
  * @author Ken Veenstra
  */
public class Gate extends JPanel
{
	private static final int ep = 4000000, eer = 100000, credits = 12489600, uridium = 20000, 
				damage4 = 20000, repbon = 4, xenomit = 200, logfiles = 2;
	private static int selectedGate = 0;
	private JPanel leftpanel, rightpanel;
	private JButton calculate;
	private Calculation calculation;
	private ButtonGroup gateSelect, designSelect, waveTrue;
	private JRadioButton selectAlfa, selectBeta, selectGamma, selectDelta, selectHonor, selectEp, selectGeen,
					wave_yes, wave_no;
	private JTextField u_ep, u_eer, u_credits, u_uridium, u_damage4, u_repbon, u_xenomit, u_logfiles;
	private int intGateSelect = 1;
	private double d_honor = 1;
	private double d_ep = 1;
	private boolean waveYesNo;
	
	public Gate()
	{
		setLayout(new BorderLayout());
		leftpanel = new JPanel();
		leftpanel.setLayout(new GridLayout(20, 2));
		rightpanel = new JPanel();
		rightpanel.setLayout(new GridLayout(20, 2));
		
		calculate = new JButton("Calculate");
		calculate.addActionListener(new Calculation());
			
		makeLeftPanel();
		makeRightPanel();
		makeGroup();
		
		leftpanel.add(new JLabel("Complete gate"));
		leftpanel.add(new JLabel());
		leftpanel.add(selectAlfa);
		leftpanel.add(selectBeta);
		leftpanel.add(selectGamma);
		leftpanel.add(selectDelta);
		leftpanel.add(new JLabel("with waves?"));
		leftpanel.add(new JLabel(""));
		leftpanel.add(wave_yes);
		leftpanel.add(wave_no);
		leftpanel.add(calculate);
		leftpanel.add(new JLabel(""));leftpanel.add(new JLabel(""));leftpanel.add(new JLabel(""));
		leftpanel.add(new JLabel("Experience points"));
		leftpanel.add(u_ep);
		leftpanel.add(new JLabel("Honor points"));
		leftpanel.add(u_eer);
		leftpanel.add(new JLabel("Credits"));
		leftpanel.add(u_credits);
		leftpanel.add(new JLabel("Uridium"));
		leftpanel.add(u_uridium);
		leftpanel.add(new JLabel("UCB-100 Munition"));
		leftpanel.add(u_damage4);
		leftpanel.add(new JLabel("Reparation tickits"));
		leftpanel.add(u_repbon);
		leftpanel.add(new JLabel("Xenomit"));
		leftpanel.add(u_xenomit);
		leftpanel.add(new JLabel("Logdisks"));
		leftpanel.add(u_logfiles);
		
		rightpanel.add(new JLabel("Designs:"));
		rightpanel.add(selectGeen);
		rightpanel.add(selectEp);
		rightpanel.add(selectHonor);
		
		add(leftpanel, BorderLayout.WEST);
		add(rightpanel, BorderLayout.EAST);
	}
	public void makeRightPanel()
	{
		selectHonor = new JRadioButton("Honordesign");
		selectHonor.setActionCommand("Honor");
		selectHonor.addActionListener(new GateHandler());
		selectEp = new JRadioButton("Ep design");
		selectEp.setActionCommand("Ep");
		selectEp.addActionListener(new GateHandler());
		selectGeen = new JRadioButton("No design");
		selectGeen.setActionCommand("Geen");
		selectGeen.addActionListener(new GateHandler());
		selectGeen.setSelected(true);
	}
	public void makeLeftPanel()
	{
		selectAlfa = new JRadioButton("Alfa");
		selectAlfa.setActionCommand("Alfa");
		selectAlfa.addActionListener(new GateHandler());
		selectAlfa.setSelected(true);
		selectBeta = new JRadioButton("Beta");
		selectBeta.setActionCommand("Beta");
		selectBeta.addActionListener(new GateHandler());
		selectGamma = new JRadioButton("Gamma");
		selectGamma.setActionCommand("Gamma");
		selectGamma.addActionListener(new GateHandler());
		selectDelta = new JRadioButton("Delta");
		selectDelta.setActionCommand("Delta");
		selectDelta.addActionListener(new GateHandler());
		wave_yes = new JRadioButton("Yes");
		wave_yes.setActionCommand("Yes");
		wave_yes.addActionListener(new GateHandler());
		wave_no = new JRadioButton("No");
		wave_no.setActionCommand("No");
		wave_no.addActionListener(new GateHandler());
		wave_no.setSelected(true);
		
		u_ep = new JTextField(10);
		u_eer = new JTextField(10);
		u_credits = new JTextField(10);
		u_uridium = new JTextField(10);
		u_damage4 = new JTextField(10);
		u_repbon = new JTextField(10);
		u_xenomit = new JTextField(10);
		u_logfiles = new JTextField(10);

	}
	public void makeGroup()
	{
		gateSelect = new ButtonGroup();
		gateSelect.add(selectAlfa);
		gateSelect.add(selectBeta);
		gateSelect.add(selectGamma);
		gateSelect.add(selectDelta);
		
		waveTrue = new ButtonGroup();
		waveTrue.add(wave_yes);
		waveTrue.add(wave_no);
		
		designSelect = new ButtonGroup();
		designSelect.add(selectHonor);
		designSelect.add(selectEp);
		designSelect.add(selectGeen);
	}
	private class GateHandler implements ActionListener
	{
		public void actionPerformed(ActionEvent b) 
		{
			if(b.getActionCommand().equals("Alfa")){intGateSelect = 1;}
			if(b.getActionCommand().equals("Beta")){intGateSelect = 2;}
			if(b.getActionCommand().equals("Gamma")){intGateSelect = 3;}
			if(b.getActionCommand().equals("Delta")){intGateSelect = 4;}
			
			if(b.getActionCommand().equals("Yes")){waveYesNo = true;}
			if(b.getActionCommand().equals("No")){waveYesNo = false;}
			
			if(b.getActionCommand().equals("Honor")){d_honor = 1.1; d_ep = 1;}
			if(b.getActionCommand().equals("Ep")){d_honor = 1; d_ep = 1.1;}
			if(b.getActionCommand().equals("Geen")){d_honor = 1; d_ep = 1;}
		}
	}

	private class Calculation implements ActionListener
	{
		public void actionPerformed(ActionEvent e)
		{
			final int waveEp = 2467200;
			final int waveHonor = 12336;
			final int waveUridium = 6488;
			int g_ep = -1;
			int g_eer = -1;
			int g_uridium = -1;
			if (e.getSource() == calculate)
			{
				if (intGateSelect != 4)
				{
					if(waveYesNo)
					{
						g_ep = (int) ((ep * intGateSelect * d_ep) + (waveEp * intGateSelect));
						g_eer = (int) ((eer * intGateSelect * d_honor) + (waveHonor * intGateSelect));
						g_uridium = (uridium * intGateSelect) + (waveUridium * intGateSelect);
					}
					else
					{
						g_ep = (int) (ep * intGateSelect * d_ep);
						g_eer = (int) (eer * intGateSelect * d_honor);
						g_uridium = uridium * intGateSelect;
					}
					int g_credits = credits * intGateSelect;
					int g_damage4 = damage4 * intGateSelect;
					int g_repbon = repbon * intGateSelect;
					int g_xenomit = xenomit * intGateSelect;
					int g_logfiles = logfiles * intGateSelect;

					u_ep.setText("" + g_ep);
					u_eer.setText("" + g_eer);
					u_credits.setText("" + g_credits);
					u_uridium.setText("" + g_uridium);
					u_damage4.setText("" + g_damage4);
					u_repbon.setText("" + g_repbon);
					u_xenomit.setText("" + g_xenomit);
					u_logfiles.setText("not good yet" + g_logfiles);
				}
				else if(intGateSelect == 4)
				{
					int deltaEp = (int) (10770400 * d_ep);
					int deltaHonor = (int) (235916 * d_honor);
					u_ep.setText("" + deltaEp);
					u_eer.setText("" + deltaHonor);
					u_credits.setText("?");
					u_uridium.setText("50332");
					u_damage4.setText("45000");
					u_repbon.setText("5");
					u_xenomit.setText("450");
					u_logfiles.setText("8");
				}
			}
		}
	}
}
